﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_306_06
    {
        //图F.64  ISYC 306-06-可转位刀片开孔钻
        public static void ISYC_306_06_g(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
          //  double sl_ = 110;
          //  double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dcin = 60.8*scale ;
            double bd = 113.4*scale ;
            double dc = 106*scale ;
            double pl = 6 * scale;
            double lu = 127.5 * scale;
            double lcf = 169*scale ;
            double ls = 57.3 * scale;
            double oal = 247.3 * scale;
            double dconms = 63 * scale;
            double df = 96.7 * scale;
            double sig = 160;
            */
            double dcin = Convert.ToDouble(data["dcin"]) * scale;
            double bd = Convert.ToDouble(data["bd"]) * scale;
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double pl = Convert.ToDouble(data["pl"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double sig = Convert.ToDouble(data["sig"]);
            double sig_ = sig * pi / 180;
            double lpr = oal - ls;
            double lta = lpr - pl;
            
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0_1, 0, oal+5);
            Vector2 p1 = fun.Polar(p0, pi / 2, bd / 2.0);
            Vector2 p2 = fun.Polar(p0, pi / -2, bd / 2.0);
            Vector2 p3 = new Vector2((8.4 / 184.0) * lta, (34.38 / 113.39) * bd );
            Vector2 p4 = fun.Polar(p3, -sig_ / 2, ((19.36 / 113.39) * bd)/2.0);
            Vector2 p5 = fun.Polar(p4, fun .CalAngle (p3,p4 ) - pi / 2, ((19.36 / 113.39) * bd)/2.0);
            Vector2 p6 = fun.Polar(p5, fun.CalAngle(p4, p3), fun.CalDistance(p4, p5) * 2);
            Vector2 p7 = fun.Polar(p6, fun.CalAngle(p6, p5) + pi / 2, fun.CalDistance(p6, p5));
            Vector2 p8 = fun.Polar(p7, fun.CalAngle(p7, p6) + pi / 2, fun.CalDistance(p7, p6));
            Vector2 p9 = fun.Polar(p5, fun.CalAngle(p5, p8) + pi / 4, fun.CalDistance(p5, p3) / 3.0);
            Vector2 p10 = fun.Polar(p6, fun.CalAngle(p6, p7) - pi / 4, fun.CalDistance(p5, p9));
            Vector2 p11 = fun.Polar(p10, fun.CalAngle(p6, p7), fun.CalDistance(p10, p9));
            Vector2 p12 = fun.Polar(p11, fun.CalAngle(p7, p8), fun.CalDistance(p10, p9));
            Vector2 p13 = fun.Inters(p6, p7, p1, p2);
            Vector2 p14 = fun.Inters(p5, p6, p1, p2);
            Vector2 p15 = new Vector2(p3.X, p3.Y -dcin -(p3.Y -p5.Y )*2);
            Vector2 p16 = fun.Polar(p15, fun.CalAngle(p3, p5), fun.CalDistance(p3, p5)); 
            Vector2 p17 = fun.Polar(p16, fun.CalAngle(p5, p6), fun.CalDistance(p5, p6));
            Vector2 p18 = fun.Polar(p17, fun.CalAngle(p6, p7), fun.CalDistance(p6, p7));
            Vector2 p19 = fun.Polar(p18, fun.CalAngle(p7, p8), fun.CalDistance(p7, p8));
            Vector2 p20 = fun.Polar(p2, 0, lta - lta * (4 / 180.0));
            Vector2 p21 = fun.Polar(p20, pi / 2, bd);
            Vector2 p22 = fun.Inters(p1, p2, p17, p18);
            Vector2 p23 = fun.Inters(p2, p20, p16, p19);
            Vector2 p24 = fun.Polar(p0, pi, pl);
            Vector2 p25_1 = fun.Polar(p24, 0,(lcf * (159 / 189.0)));
            Vector2 p25_2 = fun.Polar(p25_1, pi / 2, ls);
            Vector2 p25 = fun.Inters(p1, p21, p25_1, p25_2);
            Vector2 p26 = fun.Polar(p25, pi / -2, p1.Y / 2.0);
            Vector2 p27 = fun.Polar(p25_1, pi, p1.Y / 2.0);
            Vector2 p28 = fun.Polar(p0, pi / -2, (bd * (65.93 / 113.39)) / 2.0);
            Vector2 p29 = fun.Polar(p28, 0, lcf);
            Vector2 p30 = fun.Polar(p29, pi / 2, fun.CalDistance(p0, p28) * 2);
            Vector2 p31_0 = fun.Polar(p30, pi, oal);
            Vector2 p31 = fun.Inters(p30, p31_0, p7, p8);
            Vector2 p32 = fun.Inters(p30, p31, p25, p26);
            Vector2 p33 = fun.Polar(p28, pi / -2, fun.CalDistance(p28, p22) / 2.0);
            Vector2 p34 = fun.Polar(p2, 0, lpr / 4.2);
            Vector2 p35 = fun.Polar(p34, pi / 2, -(p34.Y - p33.Y) / 2.0);
            Vector2 p36 = fun.Polar(p33, 0, (p34.X - p33.X) + (p34.Y - p33.Y) / 2.0);
            Vector2 p37 = fun.Polar(p20, pi / 2, (bd - df) / 2.0);
            Vector2 p38 = fun.Polar(p37, 0, lta * (4.67 / 184));
            Vector2 p39 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p38, p0_1, p0_2);
            //非切削部分
            Vector2 p41 = new Vector2(oal, 0);
            Vector2 p42=fun .Polar (p41,pi/2,dconms /2.0-(dconms/10.0 ));
            Vector2 p43 = fun.Polar(p42, pi - pi / 4, (dconms / 10.0) * Math.Sqrt(2));
            Vector2 p44 = fun.Polar(p43, pi, ls - (p42.X - p43.X) * 2);
            Vector2 p45_1 = fun.Polar(p42, pi , oal );
            Vector2 p45_2 = fun.Polar(p44, pi + pi / 4, ls);
            Vector2 p45 = fun.Inters(p42, p45_1, p44, p45_2 );
            Vector2 p46_0 = fun.Polar(p45, pi, ls);
            Vector2 p46 = fun.Inters(p45, p46_0, p40, p38);
            Vector2 p47 = fun.mirrorpoint(p42, p0_1, p0_2);
            Vector2 p48 = fun.mirrorpoint(p43, p0_1, p0_2);
            Vector2 p49 = fun.mirrorpoint(p44, p0_1, p0_2);
            Vector2 p50 = fun.mirrorpoint(p45, p0_1, p0_2);
            Vector2 p51 = fun.mirrorpoint(p46, p0_1, p0_2);
            var polyline1 = Pus.AddPointsToLwPolyLine(p9,p10,p11,p12,p9);
            var polyline2 = Pus.AddPointsToLwPolyLine(p1, p13, p6,  p5, p8,p31,p32,p31, p7, p6, p14, p22, p17, p16, p23, p2, p22,
                p2, p20, p21,p25,p26,p27,p0,p14,p6,p13,p1 ,p25);
            var polyline3 = Pus.AddPointsToLwPolyLine(p28, p29, p30, p32);
            var polyline4 = Pus.AddPointsToLwPolyLine(p33, p36, p35, p34) ;
            var polyline5 = Pus.AddPointsToLwPolyLine(p39, p40, p38, p37, p38, p46, p45,p50,p45, p44, p49, p44, p43, p48, p43, p42,
                p47, p48, p49, p50, p51) ;
            polyline2.Vertexes[21].Bulge = -Math.Tan((pi/2) / 4);
            polyline4.Vertexes[1].Bulge = -Math.Tan((pi / 2) / 4);
            polyline3.Lineweight = Lineweight.W35;//Lineweight指线宽
            polyline3.Layer = refin;//Layer指图层
            polyline3.LinetypeScale = 5 * scale ;//指线性比例
            polyline3.Linetype = Linetype.Dashed ;//Linetype指是点划线还是虚线什么的
            polyline4.Lineweight = Lineweight.W35;//Lineweight指线宽
            polyline4.Layer = refin;//Layer指图层
            polyline4.LinetypeScale = 5 * scale;//指线性比例
            polyline4.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
            Circle circle1 = new Circle(p3, fun.CalDistance(p9, p11) / 6.0) ;
            dxf.AddEntity(new EntityObject[] { polyline1, polyline2,polyline3,polyline4,polyline5 
            ,circle1 
            });
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.drawcircle(dxf, p3 , fun.CalDistance(p9, p11) / 6.0, 0.5, contour);
            
            //标注
            Vector2 v1 = fun.Polar(p43, pi, fun.CalDistance(p43, p44) / 2.0);
            Vector2 v2 = fun.Polar(p2, pi + pi / 4, dc);
            Vector2 v3 = fun.Polar(p51, pi / 2, fun.CalDistance(p51, p46) / 2.0);
            Vector2 v4 = fun.Polar(v3, pi / -3, 1.6 * 1.7 * scale);
            Vector2 v5 = fun.Polar(v4, pi / -3, dconms);
            Vector2 v6 = fun.Polar(p24, pi + pi / 4, 1.6 * 1.7 * scale);
            Vector2 v7 = fun.Polar(v6, pi + pi / 4, dc / 2.0);
            fun.dimrot1(dxf, fun .Inters (p5,fun .Polar (p5,pi,ls ),p1,p2), fun.Inters(p18, fun.Polar(p18, pi, ls), p1, p2), 90, dc/4.0, 2, 3 * scale, 3.4 * scale, 0.9, "DCIN", "", "");
            fun.dimrot1(dxf, p1 , p2 , 90, dc/2.0, 2, 2.2 * scale, 2.6 * scale, 0.9, "BD", "", "");
            fun.dimrot1(dxf, fun.Inters(p7, fun.Polar(p7, pi, ls), p1, p2), fun.Inters(p16, fun.Polar(p16, pi, ls), p1, p2), 90, dc/1.5, 2, 3 * scale, 3.4 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p24, p27, 180, dc , 2, 3 * scale, 3.4 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p24, p29, 180, dc*1.3+p29.Y/2.0 , 2, 3 * scale, 3.4 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p2, p38, 180, dc * 1.6 + (p38.Y +(p2.Y-p38.Y)/2.0) , 2, 3 * scale, 3.4 * scale, 0.9, "LTA,LF", "", "");
            fun.dimrot1(dxf, p24, p38, 180, dc * 1.9 + p38.Y / 2.0, 2, 3 * scale, 3.4 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, fun .Polar (p38,pi/2,-p38.Y ), fun .Polar (p47,pi/2,-p47.Y ), 180, dc  , 2, 3 * scale, 3.4 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p24, p41, 180, dc*2.2, 2, 3 * scale, 3.4 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p43, p48, -90, dc/4.0, 2, 3 * scale, 3.4 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p40, p38, -90, dc/4.5, 2, 3 * scale, 3.4 * scale, 0.9, "DF", "", "");
            fun.dimrot1(dxf, p0, p24, 180, dc*1.6, 2, 3 * scale, 3.4 * scale, 0.9, "PL", "", "");
            fun.jdbz2(dxf, new Line(p17, p16), new Line(p6, fun .Polar (p6,sig_ /2,0.1)), dc/1.2, 3 * scale, 3.4 * scale, 0.9, "SIG", "", "");

            fun.Axis(dxf, fun.Polar(p41, -pi / 3, dc ), 0, -90, "Z", "X", "Y", 1.6 * scale, 3 * scale, 0);
            fun.Axis(dxf, fun .Polar (p51,pi/2,fun .CalDistance (p51,p46 )/2.0), 0, -90, "", "", "", 1.6 * scale, 3 * scale, 0);
            fun.Axis(dxf, p24 , 0, -90, "", "", "", 1.6 * scale, 3 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v1, 60, fun.Polar(v1,pi/3, dc / 6.0), fun.Polar(v1, pi/3, dc/3.0), 2.5 * scale, 3 * scale);
            fun.Singlelinearrow(dxf, "FDP", v2, 180, fun.Polar(v2, 0 , dc / 6.0), fun.Polar(v2, 0 , dc/3.0), 2.5 * scale, 3 * scale);
            Line linev1 = new Line(v5, v4);
            Line linev2 = new Line(v6, v7);
            Line linev3 = new Line(p0_1 , p0_2 );
            linev3.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev3.Layer = centre;//Layer指图层
            linev3.LinetypeScale = 5 * scale;//指线性比例
            linev3.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev3); //提取
            Circle circlev1 = new Circle(v3 , 1.7 * 1.6 * scale);
            Circle circlev2 = new Circle(p24, 1.7 * 1.6 * scale);
            Text txt1 = new Text("PCS,MCS", fun.Polar(v5, pi / -2, 2.5 * scale), 3 * scale,0);
            Text txt2 = new Text("CIP", fun.Polar(v7, pi / -2, 2.5 * scale), 3 * scale, 0);
            Text txt3 = new Text("ISYC=306_06", fun.Polar(p25, pi / 2, dc/2), 3 * scale, 0);
            dxf.AddEntity(new EntityObject[] { linev1,linev2 
            ,circlev1 ,circlev2 
            ,txt1 ,txt2 ,txt3 
            });

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //图F.64  ISYC 306-06-可转位刀片开孔钻
        public static void ISYC_306_06_j(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]);
           //   double sl_ = 110;
           //   double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dcin = 60.8*scale ;
            double bd = 113.4*scale ;
            double dc = 106*scale ;
            double pl = 6 * scale;
            double lu = 127.5 * scale;
            double lcf = 169*scale ;
            double ls = 57.3 * scale;
            double oal = 247.3 * scale;
            double dconms = 63 * scale;
            double df = 96.7 * scale;
            double sig = 160;
            */
            double dcin = Convert.ToDouble(data["dcin"]) * scale;
            double bd = Convert.ToDouble(data["bd"]) * scale;
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double pl = Convert.ToDouble(data["pl"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double sig = Convert.ToDouble(data["sig"]);
            double sig_ = sig * pi / 180;
            double lpr = oal - ls;
            double lta = lpr - pl;

            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0_1, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, pi / 2, bd / 2.0);
            Vector2 p2 = fun.Polar(p0, pi / -2, bd / 2.0);
            Vector2 p3 = new Vector2((8.4 / 184.0) * lta, (34.38 / 113.39) * bd);
            Vector2 p4 = fun.Polar(p3, -sig_ / 2, ((19.36 / 113.39) * bd) / 2.0);
            Vector2 p5 = fun.Polar(p4, fun.CalAngle(p3, p4) - pi / 2, ((19.36 / 113.39) * bd) / 2.0);
            Vector2 p6 = fun.Polar(p5, fun.CalAngle(p4, p3), fun.CalDistance(p4, p5) * 2);
            Vector2 p7 = fun.Polar(p6, fun.CalAngle(p6, p5) + pi / 2, fun.CalDistance(p6, p5));
            Vector2 p8 = fun.Polar(p7, fun.CalAngle(p7, p6) + pi / 2, fun.CalDistance(p7, p6));
            Vector2 p9 = fun.Polar(p5, fun.CalAngle(p5, p8) + pi / 4, fun.CalDistance(p5, p3) / 3.0);
            Vector2 p10 = fun.Polar(p6, fun.CalAngle(p6, p7) - pi / 4, fun.CalDistance(p5, p9));
            Vector2 p11 = fun.Polar(p10, fun.CalAngle(p6, p7), fun.CalDistance(p10, p9));
            Vector2 p12 = fun.Polar(p11, fun.CalAngle(p7, p8), fun.CalDistance(p10, p9));
            Vector2 p13 = fun.Inters(p6, p7, p1, p2);
            Vector2 p14 = fun.Inters(p5, p6, p1, p2);
            Vector2 p15 = new Vector2(p3.X, p3.Y - dcin - (p3.Y - p5.Y) * 2);
            Vector2 p16 = fun.Polar(p15, fun.CalAngle(p3, p5), fun.CalDistance(p3, p5));
            Vector2 p17 = fun.Polar(p16, fun.CalAngle(p5, p6), fun.CalDistance(p5, p6));
            Vector2 p18 = fun.Polar(p17, fun.CalAngle(p6, p7), fun.CalDistance(p6, p7));
            Vector2 p19 = fun.Polar(p18, fun.CalAngle(p7, p8), fun.CalDistance(p7, p8));
            Vector2 p20 = fun.Polar(p2, 0, lta - lta * (4 / 180.0));
            Vector2 p21 = fun.Polar(p20, pi / 2, bd);
            Vector2 p22 = fun.Inters(p1, p2, p17, p18);
            Vector2 p23 = fun.Inters(p2, p20, p16, p19);
            Vector2 p24 = fun.Polar(p0, pi, pl);
            Vector2 p25_1 = fun.Polar(p24, 0, (lcf * (159 / 189.0)));
            Vector2 p25_2 = fun.Polar(p25_1, pi / 2, ls);
            Vector2 p25 = fun.Inters(p1, p21, p25_1, p25_2);
            Vector2 p26 = fun.Polar(p25, pi / -2, p1.Y / 2.0);
            Vector2 p27 = fun.Polar(p25_1, pi, p1.Y / 2.0);
            Vector2 p28 = fun.Polar(p0, pi / -2, (bd * (65.93 / 113.39)) / 2.0);
            Vector2 p29 = fun.Polar(p28, 0, lcf);
            Vector2 p30 = fun.Polar(p29, pi / 2, fun.CalDistance(p0, p28) * 2);
            Vector2 p31_0 = fun.Polar(p30, pi, oal);
            Vector2 p31 = fun.Inters(p30, p31_0, p7, p8);
            Vector2 p32 = fun.Inters(p30, p31, p25, p26);
            Vector2 p33 = fun.Polar(p28, pi / -2, fun.CalDistance(p28, p22) / 2.0);
            Vector2 p34 = fun.Polar(p2, 0, lpr / 4.2);
            Vector2 p35 = fun.Polar(p34, pi / 2, -(p34.Y - p33.Y) / 2.0);
            Vector2 p36 = fun.Polar(p33, 0, (p34.X - p33.X) + (p34.Y - p33.Y) / 2.0);
            Vector2 p37 = fun.Polar(p20, pi / 2, (bd - df) / 2.0);
            Vector2 p38 = fun.Polar(p37, 0, lta * (4.67 / 184));
            Vector2 p39 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p38, p0_1, p0_2);
            //非切削部分
            Vector2 p41 = new Vector2(oal, 0);
            Vector2 p42 = fun.Polar(p41, pi / 2, dconms / 2.0 - (dconms / 10.0));
            Vector2 p43 = fun.Polar(p42, pi - pi / 4, (dconms / 10.0) * Math.Sqrt(2));
            Vector2 p44 = fun.Polar(p43, pi, ls - (p42.X - p43.X) * 2);
            Vector2 p45_1 = fun.Polar(p42, pi, oal);
            Vector2 p45_2 = fun.Polar(p44, pi + pi / 4, ls);
            Vector2 p45 = fun.Inters(p42, p45_1, p44, p45_2);
            Vector2 p46_0 = fun.Polar(p45, pi, ls);
            Vector2 p46 = fun.Inters(p45, p46_0, p40, p38);
            Vector2 p47 = fun.mirrorpoint(p42, p0_1, p0_2);
            Vector2 p48 = fun.mirrorpoint(p43, p0_1, p0_2);
            Vector2 p49 = fun.mirrorpoint(p44, p0_1, p0_2);
            Vector2 p50 = fun.mirrorpoint(p45, p0_1, p0_2);
            Vector2 p51 = fun.mirrorpoint(p46, p0_1, p0_2);
            var polyline1 = Pus.AddPointsToLwPolyLine(p9, p10, p11, p12, p9);
            var polyline2 = Pus.AddPointsToLwPolyLine(p1, p13, p6, p5, p8, p31, p32, p31, p7, p6, p14, p22, p17, p16, p23, p2, p22,
                p2, p20, p21, p25, p26, p27, p0, p14, p6, p13, p1, p25);
            var polyline3 = Pus.AddPointsToLwPolyLine(p28, p29, p30, p32);
            var polyline4 = Pus.AddPointsToLwPolyLine(p33, p36, p35, p34);
            var polyline5 = Pus.AddPointsToLwPolyLine(p39, p40, p38, p37, p38, p46, p45, p50, p45, p44, p49, p44, p43, p48, p43, p42,
                p47, p48, p49, p50, p51);
            polyline2.Vertexes[21].Bulge = -Math.Tan((pi / 2) / 4);
            polyline4.Vertexes[1].Bulge = -Math.Tan((pi / 2) / 4);
            polyline3.Lineweight = Lineweight.W35;//Lineweight指线宽
            polyline3.Layer = refin;//Layer指图层
            polyline3.LinetypeScale = 5 * scale;//指线性比例
            polyline3.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
            polyline4.Lineweight = Lineweight.W35;//Lineweight指线宽
            polyline4.Layer = refin;//Layer指图层
            polyline4.LinetypeScale = 5 * scale;//指线性比例
            polyline4.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
            Circle circle1 = new Circle(p3, fun.CalDistance(p9, p11) / 6.0);
            dxf.AddEntity(new EntityObject[] { polyline1, polyline2,polyline3,polyline4,polyline5
            ,circle1
            });
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.drawcircle(dxf, p3, fun.CalDistance(p9, p11) / 6.0, 0.5, contour);

            //标注
            Vector2 v1 = fun.Polar(p43, pi, fun.CalDistance(p43, p44) / 2.0);
            Vector2 v2 = fun.Polar(p2, pi + pi / 4, dc);
            Vector2 v3 = fun.Polar(p51, pi / 2, fun.CalDistance(p51, p46) / 2.0);
            Vector2 v4 = fun.Polar(v3, pi / -3, 1.6 * 1.7 * scale);
            Vector2 v5 = fun.Polar(v4, pi / -3, dconms);
            Vector2 v6 = fun.Polar(p24, pi + pi / 4, 1.6 * 1.7 * scale);
            Vector2 v7 = fun.Polar(v6, pi + pi / 4, dc / 2.0);
            fun.dimrot1(dxf, fun.Inters(p5, fun.Polar(p5, pi, ls), p1, p2), fun.Inters(p18, fun.Polar(p18, pi, ls), p1, p2), 90, dc / 4.0, 2, 3 * scale, 3.4 * scale, 0.9, "DCIN", "", "");
            fun.dimrot1(dxf, p1, p2, 90, dc / 2.0, 2, 2.2 * scale, 2.6 * scale, 0.9, "BD", "", "");
            fun.dimrot1(dxf, fun.Inters(p7, fun.Polar(p7, pi, ls), p1, p2), fun.Inters(p16, fun.Polar(p16, pi, ls), p1, p2), 90, dc / 1.5, 2, 3 * scale, 3.4 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p24, p27, 180, dc, 2, 3 * scale, 3.4 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p24, p29, 180, dc * 1.3 + p29.Y / 2.0, 2, 3 * scale, 3.4 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p2, p38, 180, dc * 1.6 + (p38.Y + (p2.Y - p38.Y) / 2.0), 2, 3 * scale, 3.4 * scale, 0.9, "LTA,LF", "", "");
            fun.dimrot1(dxf, p24, p38, 180, dc * 1.9 + p38.Y / 2.0, 2, 3 * scale, 3.4 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, fun.Polar(p38, pi / 2, -p38.Y), fun.Polar(p47, pi / 2, -p47.Y), 180, dc, 2, 3 * scale, 3.4 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p24, p41, 180, dc * 2.2, 2, 3 * scale, 3.4 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p43, p48, -90, dc / 4.0, 2, 3 * scale, 3.4 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p40, p38, -90, dc / 4.5, 2, 3 * scale, 3.4 * scale, 0.9, "DF", "", "");
            fun.dimrot1(dxf, p0, p24, 180, dc * 1.6, 2, 3 * scale, 3.4 * scale, 0.9, "PL", "", "");
            fun.jdbz2(dxf, new Line(p17, p16), new Line(p6, fun.Polar(p6, sig_ / 2, 0.1)), dc / 1.2, 3 * scale, 3.4 * scale, 0.9, "SIG", "", "");
            /*
            fun.Axis(dxf, fun.Polar(p41, -pi / 3, dc), 0, -90, "Z", "X", "Y", 1.6 * scale, 3 * scale, 0);
            fun.Axis(dxf, fun.Polar(p51, pi / 2, fun.CalDistance(p51, p46) / 2.0), 0, -90, "", "", "", 1.6 * scale, 3 * scale, 0);
            fun.Axis(dxf, p24, 0, -90, "", "", "", 1.6 * scale, 3 * scale, 0);
            fun.Singlelinearrow(dxf, "CCMS", v1, 60, fun.Polar(v1, pi / 3, dc / 6.0), fun.Polar(v1, pi / 3, dc / 3.0), 2.5 * scale, 3 * scale);
            fun.Singlelinearrow(dxf, "FDP", v2, 180, fun.Polar(v2, 0, dc / 6.0), fun.Polar(v2, 0, dc / 3.0), 2.5 * scale, 3 * scale);
           */ Line linev1 = new Line(v5, v4);
            Line linev2 = new Line(v6, v7);
            Line linev3 = new Line(p0_1, p0_2);
            linev3.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev3.Layer = centre;//Layer指图层
            linev3.LinetypeScale = 5 * scale;//指线性比例
            linev3.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev3); //提取
            Circle circlev1 = new Circle(v3, 1.7 * 1.6 * scale);
            Circle circlev2 = new Circle(p24, 1.7 * 1.6 * scale);
            Text txt1 = new Text("PCS,MCS", fun.Polar(v5, pi / -2, 2.5 * scale), 3 * scale, 0);
            Text txt2 = new Text("CIP", fun.Polar(v7, pi / -2, 2.5 * scale), 3 * scale, 0);
            Text txt3 = new Text("ISYC=306_06", fun.Polar(p25, pi / 2, dc / 2), 3 * scale, 0);
            /*dxf.AddEntity(new EntityObject[] { linev1,linev2
            ,circlev1 ,circlev2
            ,txt1 ,txt2 ,txt3
            });*/

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}